/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.declex;

import ohos.aafwk.ability.Ability;
import ohos.agp.components.AttrHelper;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.BaseDialog;

import com.dspot.declex.actions.AlertDialogGate;
import com.dspot.declex.annotation.Model;
import com.dspot.declex.annotation.Populate;
import com.dspot.declex.annotation.PutOnAction;
import com.dspot.declex.annotation.Recollect;
import com.example.declex.model.User_;

import org.ohosannotations.annotations.AfterInject;
import org.ohosannotations.annotations.Click;
import org.ohosannotations.annotations.ComponentById;
import org.ohosannotations.annotations.EAbility;

import static com.dspot.declex.actions.Action.$AlertDialog;

/**
 * @since 2021-07-24
 */
@EAbility(ResourceTable.Layout_ability_populate_view)
public class PopulateViewsAbility extends Ability {

    @Model(query = "Id = 1")
    @Recollect
    @Populate
    @PutOnAction(ResourceTable.Id_save)
    User_ user;//注入被@UseModel的model

    @AfterInject
    void afterInject() {//user被注入之后回调

    }

    @Click
    void back() {
//        $AlertDialog().message("continue?").positiveButton(ResourceTable.Media_icon).negativeButton(ResourceTable.Media_icon)
        $AlertDialog().message("continue?").positiveButton("YES").negativeButton("NO")
            .setView(ResourceTable.Layout_commdialog_text)
            .view(AttrHelper.vp2px(300,getContext()),AttrHelper.vp2px(80,getContext()));
        if ($AlertDialog.PositiveButtonPressed) {
            $AlertDialog.PositiveButtonPressed().dialog.destroy();
            this.terminateAbility();
        }
        if ($AlertDialog.NegativeButtonPressed) {
            $AlertDialog.NegativeButtonPressed().dialog.destroy();
        }

    }


}
